package com.arpa.oms.domain.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.arpa.wms.domain.entity.BasicEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * OMS销售单
 * </p>
 *
 * @author LEO
 * @since 2020-10-22
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("oms_sale")
@ApiModel(value = "OmsSale对象", description = "OMS销售单")
public class Sale extends BasicEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "销售单号")
    @TableField("code")
    @NotEmpty(message = "销售单号不可为空！", groups = {Update.class})
    private String code;

    @ApiModelProperty(value = "来源单号")
    @TableField("source_code")
    private String sourceCode;

    @ApiModelProperty(value = "仓库")
    @TableField("warehouse_code")
    @NotEmpty(message = "仓库编号不能为空！", groups = {Save.class,Update.class})
    private String warehouseCode;

    @ApiModelProperty(value = "入驻商")
    @TableField("shipment_code")
    @NotEmpty(message = "货主编号不能为空！", groups = {Save.class,Update.class})
    private String shipmentCode;

    @ApiModelProperty(value = "入驻商")
    @TableField("shipment_name")
    @NotEmpty(message = "货主名称不能为空！", groups = {Save.class})
    private String shipmentName;

    @ApiModelProperty(value = "所属机构Code")
    @TableField("group_code")
    private String groupCode;

    @ApiModelProperty(value = "销售类型 normal:普通销售", allowableValues ="普通销售")
    @TableField("sale_type")
    private String saleType;

    @ApiModelProperty(value = "客户")
    @TableField("customer_code")
    @NotEmpty(message = "客户编号不能为空！", groups = {Save.class,Update.class})
    private String customerCode;

    @ApiModelProperty(value = "订单数量（销售单位）")
    @TableField("plan_quantity")
    private BigDecimal planQuantity;

    @ApiModelProperty(value = "实际销售数量（销售单位），即出库数量（销售单位）")
    @TableField("actual_quantity")
    private BigDecimal actualQuantity;

    @ApiModelProperty(value = "订单数量（基本单位）")
    @TableField("plan_basic_quantity")
    private BigDecimal planBasicQuantity;

    @ApiModelProperty(value = "实际销售数量（基本单位），即出库数量（销售单位）")
    @TableField("actual_basic_quantity")
    private BigDecimal actualBasicQuantity;

    @ApiModelProperty(value = "退货数量（基本单位）")
    @TableField("refund_basic_quantity")
    private BigDecimal refundBasicQuantity;

    @ApiModelProperty(value = "退货数量（销售单位）")
    @TableField("refund_quantity")
    private BigDecimal refundQuantity;

    @ApiModelProperty(value = "付款金额")
    @TableField("payment_amount")
    private BigDecimal paymentAmount;

//    @ApiModelProperty(value = "已使用付款金额，用于批次生成付款明细时，计算已使用的付款金额数量")
//    @Digits(integer = 14,fraction = 6)
//    @TableField("use_payment_amount")
//    private BigDecimal usePaymentAmount;

    @ApiModelProperty(value = "欠款金额")
    @TableField("owed_amount")
    private BigDecimal owedAmount;

    @ApiModelProperty(value = "状态：新增、作废、待审核、审核通过、审核未通过")
    @TableField("status")
    private String status;

    @ApiModelProperty(value = "备注")
    @TableField("remarks")
    @Length(max = 255, message = "备注长度不能大于255", groups = {Save.class, Update.class})
    private String remarks;

    @ApiModelProperty(value = "优惠金额")
    @TableField("discount_amount")
    @DecimalMin(value = "0", message = "优惠金额不能为负数", groups = {Sale.Save.class, Sale.Update.class})
    private BigDecimal discountAmount;

    @ApiModelProperty(value = "结算金额")
    @TableField("pay_amount")
    @DecimalMin(value = "0", message = "结算金额不能为负数", groups = {Sale.Save.class, Sale.Update.class})
    private BigDecimal payAmount;

    @ApiModelProperty(value = "其他费用")
    @TableField("other_amount")
    @DecimalMin(value = "0", message = "其他费用不能为负数", groups = {Sale.Save.class, Sale.Update.class})
    private BigDecimal otherAmount;

    @ApiModelProperty(value = "店铺编码code")
    @TableField("shop_code")
    private String shopCode;

    @ApiModelProperty(value = "店铺名称")
    @TableField("shop_name")
    private String shopName;

    @ApiModelProperty(value = "承运商编码code")
    @TableField("carrier_code")
    private String carrierCode;

    @ApiModelProperty(value = "承运商名称")
    @TableField("carrier_name")
    private String carrierName;

    @ApiModelProperty(value = "买家姓名")
    @TableField("buyer_name")
    private String buyerName;

    @ApiModelProperty(value = "买家电话")
    @TableField("buyer_mobile")
    private String buyerMobile;

    @ApiModelProperty(value = "区域信息")
    @TableField(exist = false)
    private List<String> areaList;

    @ApiModelProperty(value = "国家")
    @TableField("country_name")
    private String countryName;

    @ApiModelProperty(value = "省")
    @TableField("province_name")
    private String provinceName;

    @ApiModelProperty(value = "市")
    @TableField("city_name")
    private String cityName;

    @ApiModelProperty(value = "区县")
    @TableField("county_name")
    private String countyName;

    @ApiModelProperty(value = "买家地址")
    @TableField("buyer_address")
    @Length(max = 500, message = "地址长度不能大于500", groups = {Save.class, Update.class})
    private String buyerAddress;

    @ApiModelProperty(value = "拆单状态，0-未拆，1-已拆")
    @TableField("unpack_status")
    private String unpackStatus;

    @ApiModelProperty(value = "合单号")
    @TableField("merge_code")
    private String mergeCode;

    @ApiModelProperty(value = "审核意见")
    @TableField("verify_opinion")
    private String verifyOpinion;

    @ApiModelProperty(value = "审核人")
    @TableField("verify_by")
    private String verifyBy;

    @ApiModelProperty(value = "审核人姓名")
    @TableField("verify_name")
    private String verifyName;

    @ApiModelProperty(value = "wms返回信息")
    @TableField("wms_message")
    private String wmsMessage;

    @ApiModelProperty(value = "下单时间")
    @TableField("third_order_time")
    private LocalDateTime thirdOrderTime;

    @ApiModelProperty(value = "支付时间")
    @TableField("third_pay_time")
    private LocalDateTime thirdPayTime;

    @ApiModelProperty(value = "面单号")
    @TableField("waybill_code")
    private String waybillCode;
    /**
     * 审核时间
     * 自动填充
     */
    @ApiModelProperty(hidden = true)
    @TableField(value = "gmt_verify")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime gmtVerify;

    @ApiModelProperty(value = "销售明细")
    @TableField(exist = false)
    @Valid
    private List<SaleItem> saleItemList;

    @ApiModelProperty(value = "平台标识")
    @TableField("platform_code")
    private String platformCode;

    @ApiModelProperty(value = "平台名称")
    @TableField("platform_name")
    private String platformName;

    @ApiModelProperty(value = "快递单号（来自拼多多）")
    @TableField("tracking_number")
    private String trackingNumber;

    @ApiModelProperty(value = "快递公司在拼多多的代码")
    @TableField("logistics_id")
    private Long logisticsId;

    @ApiModelProperty(value = "买家留言")
    @TableField("buyer_message")
    private String buyerMessage;

    @ApiModelProperty(value = "订单类型")
    @TableField("order_type")
    private String orderType;

    @ApiModelProperty(value = "商城商家编码")
    @TableField("e_customer_code")
    private String eCustomerCode;

    @ApiModelProperty(value = "面单商家编码")
    @TableField("ew_customer_code")
    private String ewCustomerCode;



    public interface Save{

    }
    public interface Update{

    }

}
